package com.file.controller;

import com.file.csv.read.ReadCSV;
import com.file.csv.service.impl.CVSServiceImpl;
import com.file.csv.write.WriteCSV;
import com.file.sql.service.SQLService;
import com.file.sql.service.impl.SQLServiceImpl;
import com.file.txt.pojo.TxtUser;
import com.file.txt.service.impl.TxtDataServiceImpl;
import com.file.txt.utils.TransBeanUtils;
import com.file.xml.pojo.Xml;
import com.file.xml.service.impl.XmlDataServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
public class FileController {

    @Autowired
    private XmlDataServiceImpl xmlDataService;

    @Autowired
    private TxtDataServiceImpl txtDataService;

    @Autowired
    private CVSServiceImpl cvsService;

    @Autowired
    private SQLServiceImpl sqlService;

    @RequestMapping(value = "/readerXml", method = RequestMethod.GET)
    public void readerXml() throws Exception {
        List<Xml> xmlList = xmlDataService.listXml();
        for (Xml xml : xmlList) {
            System.out.println(xml.getCityId());
        }
    }

    @RequestMapping(value = "/readerTxt", method = RequestMethod.GET)
    public void readerTxt() throws Exception {
        List<TxtUser> txtUsers = TransBeanUtils.resolverTxt("D:\\TxtUser.txt", TxtUser.class, ",");
        for (TxtUser txtUser : txtUsers) {
            System.out.println(txtUser.getId());
        }
    }

    @RequestMapping(value = "/readerCSV", method = RequestMethod.GET)
    public void readerCSV() throws Exception {
        cvsService.readCSV("D:\\Test.csv");
    }

    @RequestMapping(value = "/writeCSV", method = RequestMethod.GET)
    public void writeCSV() throws Exception {
        cvsService.writeCSV("D:\\Test.csv");
    }

    @RequestMapping(value = "/peekSQL", method = RequestMethod.GET)
    public void peekSQL() throws Exception {
        sqlService.ListSQL();
    }



}
